// 
// api.js
// 客户后台
// 
// Created by 区区电脑 on 2024/09/03.
// 

import request from '@/request'

// 列表
export function GetProgramList(data = {}) {
    return request({url: '/api/Program/GetProgramList', method: 'post', data})
}


/**
 * 查询最新版本
 * @param params
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function GetNewVersion(params) {
    return request({url: "/api/Version/GetNewVersion", method: 'get', params})
}

/**
 * 版本分页列表
 * @param params
 * @param data
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function GetVersionPageList(params, data = {}) {
    return request({url: '/api/Version/GetVersionPageList', method: 'post', params, data})
}


/**
 * 文件下载
 * @param data
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function CollectFullFiles(data = {}) {
    return request({url: '/api/VersionFile/CollectFullFiles', method: 'post', data})
}

/**
 * 文件更新
 * @param data
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function CollectUpdateFiles(data = {}) {
    return request({url: '/api/VersionFile/CollectUpdateFiles', method: 'post', data})
}

/**
 * 文件下载（新）
 * @param data
 * @returns {Promise | Promise<unknown> | *}
 * @constructor
 */
export function DownloadVersionFiles(data = {}, fileName) {
    if (!fileName) {
        return $message.warning('请输入文件名');
    }
    return request({url: '/api/VersionFile/DownloadVersionFiles', method: 'post', data, responseBlob: true}).then(res => {
        if (res.data) {
            const downloadUrl = URL.createObjectURL(res.data);
            const a = document.createElement("a");
            a.download = `${fileName}`;
            a.href = downloadUrl;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            window.URL.revokeObjectURL(downloadUrl);
            return {
                success: true,
            }
        } else {
            $message.error("请确认您的 软件类型、探测器类型、mac 码是否正确");
            return {
                success: false,
            }
        }
    })
}